﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using TankGame2013;

namespace GameTank
{

    /// <summary>
    /// This is a game component that draw a image.
    /// </summary>
    public class ImageComponent : VisibleGameEntity
    {
        public enum DrawMode
        {
            Center = 1,
            Stretch,
        };

        // Texture to draw
        protected readonly Texture2D texture;
        // Draw Mode
        protected readonly DrawMode drawMode;
        // Spritebatch
        protected SpriteBatch spriteBatch = null;
        // Image Rectangle
        protected Rectangle imageRect;
        private Vector2 _pos;

        public Vector2 Pos
        {
            get { return _pos; }
            set { _pos = value; }
        }

        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="game">The game object</param>
        /// <param name="texture">Texture to Draw</param>
        /// <param name="drawMode">Draw Mode</param>
        public ImageComponent(Texture2D texture, DrawMode drawMode)
        {
            this.texture = texture;
            this.drawMode = drawMode;
            // Get the current spritebatch
            // Create a rectangle with the size and position of the image
            switch (drawMode)
            {
                case DrawMode.Center:
                    imageRect = new Rectangle((Game1.windowsBounder.Width -
                        texture.Width) / 2, (Game1.windowsBounder.Height -
                        texture.Height) / 2, texture.Width, texture.Height);
                    break;
                case DrawMode.Stretch:
                    imageRect = new Rectangle(0, 0, Game1.windowsBounder.Width,
                        Game1.windowsBounder.Height);
                    break;
            }
        }

        public ImageComponent(Texture2D texture, Vector2 pos)
        {
            this.texture = texture;
            this.Pos = pos;
        }

        /// <summary>
        /// Allows the game component to draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Draw(GameTime gameTime ,SpriteBatch spriteBatch)
        {
            spriteBatch.Begin();
            spriteBatch.Draw(texture, imageRect, Color.White);
            spriteBatch.End();
        }
    }
}
